using AutoMapper;
using System.Collections.Generic;

namespace hao_Common.AutoMapper.Services
{
    /// <summary>
    /// 映射服务实现
    /// </summary>
    public class MapperService : IMapperService
    {
        private readonly IMapper _mapper;
        
        public MapperService(IMapper mapper)
        {
            _mapper = mapper;
        }
        
        public TDestination Map<TDestination>(object source)
        {
            return _mapper.Map<TDestination>(source);
        }
        
        public TDestination Map<TSource, TDestination>(TSource source)
        {
            return _mapper.Map<TSource, TDestination>(source);
        }
        
        public TDestination Map<TSource, TDestination>(TSource source, TDestination destination)
        {
            return _mapper.Map(source, destination);
        }
        
        public IEnumerable<TDestination> Map<TSource, TDestination>(IEnumerable<TSource> source)
        {
            return _mapper.Map<IEnumerable<TSource>, IEnumerable<TDestination>>(source);
        }
        
        public List<TDestination> MapList<TSource, TDestination>(IEnumerable<TSource> source)
        {
            return _mapper.Map<List<TDestination>>(source);
        }
    }
}